package com.controller;

import com.dao.SysUser;
import com.dao.dto.SysUserUpdateDTO;
import com.service.SysUserService;
import com.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/regist")
public class RegisterLoginController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 注册
     * @param sysUser
     * @return
     */
    @RequestMapping(value = "/registLogin", method = RequestMethod.POST)
    public Result registLogin(@RequestBody SysUser sysUser){
        return sysUserService.registryLogin(sysUser);
    }

    /**
     * 登录
     * @param
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Result login(@RequestBody SysUser sysUser){
        return sysUserService.login(sysUser);
    }

    /**
        @author madSong
        @since 2024/5/10
        @description  修改密码
    */
    @PostMapping("/updatePwd")
    public Result updatePwd(@RequestBody @Validated SysUserUpdateDTO sysUserUpdateDTO,
                            BindingResult bindingResult){

        if(bindingResult.hasErrors()){
            String message = bindingResult.getFieldError().getDefaultMessage();
            return Result.fail(message);
        }
        Result result = new Result();
        result = sysUserService.updatePwd(sysUserUpdateDTO);
        return result;
    }



}
